package reflect;

import reflect.annotation.AutoRunClass;
import reflect.annotation.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        System.out.println("输入一个类名");
        String classname = scan.next();
        Class cls = Class.forName(classname);
        if (cls.isAnnotationPresent(AutoRunClass.class)){
            System.out.println(classname+"被标注了");
            Object obj = cls.newInstance();
            Method[] method = cls.getMethods();
            for (Method method1 : method){
                if (method1.isAnnotationPresent(AutoRunMethod.class)){
                    method1.invoke(obj);
                }
            }
        }else {
            System.out.println("该类没有被标注");
        }
    }
}
